package com.yunwaikeji.gy_tool_library.utils.display;

import android.content.Context;
import android.graphics.Path;
import android.graphics.RectF;

public class GYPathBuilder {
    private final float width;
    private final float height;
    private float radiusLeftTopPx = 0;
    private float radiusRightTopPx = 0;
    private float radiusRightBottomPx = 0;
    private float radiusLeftBottomPx = 0;
    private float edgeWidthPx = 0;

    public GYPathBuilder(float width, float height) {
        this.width = width;
        this.height = height;
    }

    public GYPathBuilder setRadiusLeftTopPx(float radiusLeftTopPx) {
        this.radiusLeftTopPx = radiusLeftTopPx;
        return this;
    }

    public GYPathBuilder setRadiusLeftTopDp(Context context, int radiusLeftTopDp) {
        return setRadiusLeftTopPx(GYDisplayUtils.dp2px(context, radiusLeftTopDp));
    }

    public GYPathBuilder setRadiusRightTopPx(float radiusRightTopPx) {
        this.radiusRightTopPx = radiusRightTopPx;
        return this;
    }

    public GYPathBuilder setRadiusRightTopDp(Context context, int radiusRightTopDp) {
        return setRadiusRightTopPx(GYDisplayUtils.dp2px(context, radiusRightTopDp));
    }

    public GYPathBuilder setRadiusRightBottomPx(float radiusRightBottomPx) {
        this.radiusRightBottomPx = radiusRightBottomPx;
        return this;
    }

    public GYPathBuilder setRadiusRightBottomDp(Context context, int radiusRightBottomDp) {
        return setRadiusRightBottomPx(GYDisplayUtils.dp2px(context, radiusRightBottomDp));
    }

    public GYPathBuilder setRadiusLeftBottomPx(float radiusLeftBottomPx) {
        this.radiusLeftBottomPx = radiusLeftBottomPx;
        return this;
    }

    public GYPathBuilder setRadiusLeftBottomDp(Context context, int radiusLeftBottomDp) {
        return setRadiusLeftBottomPx(GYDisplayUtils.dp2px(context, radiusLeftBottomDp));
    }

    public GYPathBuilder setEdgeWidthPx(float edgeWidthPx) {
        this.edgeWidthPx = edgeWidthPx;
        return this;
    }

    public GYPathBuilder setEdgeWidthDp(Context context, float edgeWidthDp) {
        return setEdgeWidthPx(GYDisplayUtils.dp2px(context, edgeWidthDp));
    }

    public Path build() {
        Path path = new Path();
        path.moveTo(edgeWidthPx, radiusLeftTopPx + edgeWidthPx);
        //左上角
        path.arcTo(new RectF(edgeWidthPx, edgeWidthPx, radiusLeftTopPx * 2 + edgeWidthPx, radiusLeftTopPx * 2 + edgeWidthPx), 180, 90);
        //上直线
        path.lineTo(width - radiusRightTopPx - edgeWidthPx, edgeWidthPx);
        //右上角
        path.arcTo(new RectF(width - radiusRightTopPx * 2 - edgeWidthPx, edgeWidthPx, width - edgeWidthPx, radiusRightTopPx * 2 + edgeWidthPx), -90, 90);
        //右直线
        path.lineTo(width - edgeWidthPx, height - radiusRightBottomPx - edgeWidthPx);
        //右下角
        path.arcTo(new RectF(width - radiusRightBottomPx * 2 - edgeWidthPx, height - radiusRightBottomPx * 2 - edgeWidthPx, width - edgeWidthPx, height - edgeWidthPx), 0, 90);
        //下直线
        path.lineTo(radiusLeftBottomPx + edgeWidthPx, height - edgeWidthPx);
        //左下角
        path.arcTo(new RectF(edgeWidthPx, height - radiusLeftBottomPx * 2 - edgeWidthPx, radiusLeftBottomPx * 2 + edgeWidthPx, height - edgeWidthPx), 90, 90);
        //左边直线
        path.lineTo(edgeWidthPx, radiusLeftTopPx + edgeWidthPx);
        return path;
    }
}
